<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
	</body>
	<script>
		//创建XHR对象
		function createXHR() {
			//标准浏览器
			if(typeof XMLHttpRequest != "undefined") {
				return new XMLHttpRequest();
				// IE浏览器
			} else if(typeof ActiveXObject != "undefined") {
				if(typeof arguments.callee.activeXString != "string") {
					var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp"],
						i = 0,
						len = versions.length;
					//遍历并设置版本
					for(; i < len; i++) {
						try {
							new ActiveXObect(versions[i]);
							arguments.callee.activeXString = versions[i];
							break;
						} catch(ex) {}
					}
				}
				return new ActiveXObect(arguments.callee.activeXString);
				//对不支持的浏览器抛出错误提示
			} else {
				throw new Error("您的浏览器并不支持Ajax.");
			}
		}
		
		console.log(createXHR())
	</script>

</html>